
name: 'Ingest Cache Build'
description: 'Restore ingest specific cache on top of base cache, recreate if not found'
inputs:
  python-version:
    description: 'python version associated with the cache'
    required: true
  check-only:
    description: 'if set, will not restore the cache if it exists'
    default: "false"
runs:
  using: "composite"
  steps:
    - name: Check for/restore ingest cache
      uses: actions/cache/restore@v3
      id: ingest-virtualenv-cache-restore
      with:
        path: |
          .venv
          nltk_data
        key: unstructured-ingest-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('requirements/ingest/*.txt') }}
        lookup-only: ${{ inputs.check-only }}
    - name: Restore base virtual environment
      if: steps.ingest-virtualenv-cache-restore.outputs.cache-hit != 'true'
      uses: ./.github/actions/base-cache
      with:
        python-version: ${{ inputs.python-version }}
    - name: Set up Python ${{ inputs.python-version }}
      if: steps.ingest-virtualenv-cache-restore.outputs.cache-hit != 'true'
      uses: actions/setup-python@v4
      with:
        python-version: ${{ inputs.python-version }}
    - name: Setup virtual environment (no cache hit)
      if: steps.ingest-virtualenv-cache-restore.outputs.cache-hit != 'true'
      shell: bash
      run: |
        python${{ inputs.python-version }} -m venv .venv
        source .venv/bin/activate
        make install-all-ingest
    - name: Save Ingest Cache
      if: steps.ingest-virtualenv-cache-restore.outputs.cache-hit != 'true'
      id: ingest-virtualenv-cache-save
      uses: actions/cache/save@v3
      with:
        path: |
          .venv
          nltk_data
        key: unstructured-ingest-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('requirements/ingest/*.txt') }}

